<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_SESSION['os']!='windows'){
    exi('这个只有PC端，请在PC页面登录！','error');
}
set_html('title','登录用户');
if($_RQ['op']=='get'){
	$return['set']=$this->plugin_setting('setting');
	$return['set']['loginlogo']=tomedia($return['set']['loginlogo']);
	$return['set']['loginbg']=tomedia($return['set']['loginbg']);
	if($_SESSION['os']=='windows'){
		$return['session_id']=session_id();
	}
	if($_SESSION['uid']){
		//$_SESSION['uid']='';
		//exi('','error','jy_lvpai/manage.index/');
	}
	$_SESSION['logout_forward']='jy_lvpai/login/';
	$_SESSION['forward_url']='jy_lvpai/manage.index/'; 
	$return['forward_url']=base64_encode($_SESSION['forward_url']);
	$return['info']=array();
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['password'] || !$post['username']){
		exi('请填写账户名和密码','error');
	}
	$user=pdo_get('jy_lvpai_member',array('uniacid'=>$_SESSION['uniacid'],'uname'=>$post['username']));
	if(!$user || $post['password']!=base64_decode($user['upass'])){
		exi('用户名或密码错误','error');
	}
	if($user['endtime']<time()){
		exi('账户已到期，请续费！','error');
	}
	if(!$user['mid']){
		do{
			$username='user_'.random(10);
		}while(pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'username'=>$username),'id'));
		$member=array('username'=>$username,'password'=>trim($user['upass']));
		$uid=model('core/member')->register($member);
		pdo_update('jy_lvpai_member',array('mid'=>$uid),array('id'=>$user['id'],'uniacid'=>$_SESSION['uniacid']));
		//exi('该机构没有绑定用户/管理员！','error');
	}
	$_SESSION['uid']=$user['mid']?:$uid;
	$_SESSION['memberid']=$user['id'];
	$_SESSION['member']['username']=$user['uname'];
	//绝对地址，会刷新页面
	$url=custom_url('jy_lvpai/manage.index/',true);
	exi('登陆成功!','',$url);
	
}